package easy.id_0_100;

import easy.pojo.ListNode;

public class lee21 {


    public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
        ListNode pre=new ListNode();
        ListNode cur=pre;
        ListNode cur1=list1;
        ListNode cur2=list2;
        while(cur1!=null|| cur2!=null){
            if(cur1!=null&&cur2!=null){
                if(cur1.val<=cur2.val){
                    cur.next=cur1;
                    cur1=cur1.next;
                }else{
                    cur.next=cur2;
                    cur2=cur2.next;
                }
                cur=cur.next;
            }else if(cur1!=null){
                cur.next=cur1;
                cur1=cur1.next;
                cur=cur.next;
            }else{
                cur.next=cur2;
                cur2=cur2.next;
                cur=cur.next;
            }
        }
        return pre.next;
    }
}
